package com.twu.biblioteca.models;


import java.util.Calendar;

public class Book {
    private Long id;
    private String name;
    private String author;
    private Integer yearPublished;
    private boolean checkout;
    private User user;

    public Book(long id, String name, String author, int yearPublished, boolean checkout) {

        if (name == null || name.equals("") || author == null || author.equals("")){
            throw new IllegalArgumentException();
        }

        Calendar instant = Calendar.getInstance();
        int instantYear = instant.get(Calendar.YEAR);

        if(yearPublished < 0 || yearPublished > instantYear){
            throw new IllegalArgumentException();
        }

        this.id = new Long(id);
        this.name = name;
        this.author = author;
        this.yearPublished = new Integer(yearPublished);
        this.checkout = checkout;
        this.user = null;
    }

    @Override
    public String toString() {
        return this.name;
    }

    public String getName() {
        return name;
    }

    public String getAuthor() {
        return author;
    }

    public Integer getYearPublished() {
        return yearPublished;
    }

    public Long getId() {
        return id;
    }

    public boolean isCheckout() {
        return checkout;
    }

    public void setCheckout(boolean checkout) {
        this.checkout = checkout;
    }

    public void setUser(User user) {
        this.user = user;
    }
}
